#include<stdio.h>
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,m;
    scanf("%d %d",&n,&m);
    //printf("%d %d\n",n,m);
    int x[n+10][n+10];
    int temp[n+10][n+10];
    int k = 0;
    for(int i = 1; i <= n;i++)
    {
        for(int j = 1; j <=n;j++)
        {
            x[i][j] = ++k;
        }
    }
    for(int i = 0; i < m; i++)
    {
        int x1,y,r,z;
        scanf("%d %d %d %d",&y,&x1,&r,&z);
        //printf("%d %d %d %d\n",x1,y,r,z);
        if(z == 0)
        {
            for(int m = y - r; m <= y+r; m++)
            {
                for(int n = x1-r; n <= x1+r; n++)
                {
                    //printf("%d %d %d %d\n",m,n,n+y-x1,x1+y-m);
                    temp[n+y-x1][x1+y-m] = x[m][n];
                }
            }
            for(int m = y - r; m <= y+r; m++)
            {
                for(int n = x1-r; n <= x1+r; n++)
                {
                    x[m][n] = temp[m][n];
                }
            }
        }
        else
        {
            for(int m = y - r; m <= y+r; m++)
            {
                for(int n = x1-r; n <= x1+r; n++)
                {
                    //printf("%d %d %d %d\n",m,n,y+x1-n,m+x1-y);
                    temp[y+x1-n][m+x1-y] = x[m][n];
                }
            }
            for(int m = y - r; m <= y+r; m++)
            {
                for(int n = x1-r; n <= x1+r; n++)
                {
                    x[m][n] = temp[m][n];
                }
            }
        }
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            if (j < n) printf("%d ",x[i][j]);
            else printf("%d",x[i][j]);
        }
        printf("\n");
    }
}